package com.skyline.attraction.dao.impl;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Repository;

import com.skyline.attraction.dao.RatyDao;
import com.skyline.attraction.type.RatyType;
import com.skyline.base.dao.impl.BaseDaoImpl;

@Repository("ratyDao")
public class RatyDaoImpl extends BaseDaoImpl implements RatyDao {
	/**
	 * insert into raty(tarId,type,userId,ratyStar,ratyTime)
	 * values(?,?,?,?,current_timestamp)
	 */
	@Value("${RatyDao.insertRaty}")
	private String insertRatySql;
	/**
	 * count (1) from raty where tarId=? and userId =? and type=?
	 */
	@Value("${RatyDao.countUserRaty}")
	private String countUserRatySql;

	@Override
	public void insertRaty(Long targetId, RatyType type, Long userId, Integer ratyStar) {
		jdbcTemplate.update(insertRatySql, targetId, type.toString(), userId, ratyStar);

	}

	@Override
	public Integer countUserRaty(Long targetId, RatyType type, Long userId) {
		return jdbcTemplate.queryForInt(countUserRatySql, targetId, userId, type.toString());
	}

}
